﻿
CREATE PROCEDURE [dbo].[proc_Customer_Update]
	(
		@CustomerId uniqueidentifier,
		@CustomerName nvarchar(200),
		@Project nvarchar(200),
		@WebAddress nvarchar(100),
		@Tel nvarchar(50),
		@Fax nvarchar(50),
		@Address nvarchar(200),
		@Zip nvarchar(20),
		@IndustryOneId int,
		@IndustryTwoId int,
		@SourceId int,
		@TypeId int,
		@StateId int,
		@ProtectId int,
		@pid int,
		@cid int,
		@Rid int,
		@SalesPerson nvarchar(50),
		@ServicePerson nvarchar(50),
		@MnemonicWorks nvarchar(50)
	)
AS
Begin
	Declare	@CustomerName_Old nvarchar(200)
	Declare	@MnemonicWorks_Old nvarchar(50)
	Declare	@WebAddress_Old nvarchar(100)
	Declare	@Tel_Old nvarchar(50)
	Declare	@Fax_Old nvarchar(50)
	Declare	@Address_Old nvarchar(200)
	Declare	@Zip_Old nvarchar(20)
	Declare	@IndustryOneId_Old int
	Declare	@IndustryTwoId_Old int
	Declare	@SourceId_Old int
	Declare	@TypeId_Old int
	Declare	@StateId_Old int
	Declare	@pid_Old int
	Declare	@cid_Old int
	Declare	@Rid_Old int
	
	Select @CustomerName_Old=CustomerName,@MnemonicWorks_Old=MnemonicWorks,@pid_Old=Pid,
			@cid_Old=Cid,@Rid_Old=Rid,@Address_Old=Address,@SourceId_Old=SourceId,@Zip_Old=Zip,@Fax_Old=Fax,
			@IndustryOneId_Old=IndustryOneId,@IndustryTwoId_Old=IndustryTwoId,@SourceId_Old=SourceId,
			@TypeId_Old=TypeId,@StateId_Old=StateId,@Tel_Old=Tel,@WebAddress_Old=WebAddress
	 From Customer
	Where CustomerId = @CustomerId

	Update Customer SET 
	    CustomerName=@CustomerName,
	    MnemonicWorks=@MnemonicWorks,
	    Project=@Project,
	    Pid=@pid,
	    Cid=@cid,
		Rid=@Rid,
	    Address=@Address,
	    SourceId=@SourceId,
        StateId=@StateId,
	    TypeId=@TypeId,
        IndustryOneId=@IndustryOneId,
        IndustryTwoId=@IndustryTwoId,
	    Zip=@Zip,
	    WebAddress=@WebAddress,
	    Fax=@Fax
--		Tel=@Tel,
--		ProtectId=@ProtectId,
--		SalesPerson=@SalesPerson,
--		ServicePerson=@ServicePerson,
	Where CustomerId = @CustomerId

	Update [Order] Set CusName=@CustomerName Where CusId=@CustomerId
	Update [Order_PaymentRecord] Set CusName=@CustomerName Where CusId=@CustomerId
	Update [Project] Set CusName=@CustomerName Where CusId=@CustomerId
/*
 * 2016/2/22 增加客户资料修改记录
 */
INSERT INTO [dbo].[Customer_Update_Log]
           ([CustomerId],[CustomerName_Old],[CustomerName_New],[MnemonicWorks_Old],[MnemonicWorks_New],
		   [Pid_Old],[Pid_New],[Cid_Old],[Cid_New],[Rid_Old],[Rid_New],[Address_Old],[Address_New],
		   [SourceId_Old],[SourceId_New],[StateId_Old],[StateId_New],[TypeId_Old],[TypeId_New],
           [IndustryOneId_Old],[IndustryOneId_New],[IndustryTwoId_Old],[IndustryTwoId_new],
		   [Zip_Old],[Zip_New],[WebAddress_Old],[WebAddress_New],[Fax_Old],[Fax_New])
     VALUES(@CustomerId,@CustomerName_Old,@CustomerName,@MnemonicWorks_Old,@MnemonicWorks,@pid_Old,@pid,
	 @cid_Old,@cid,@Rid_Old,@Rid,@Address_Old,@Address,@SourceId_Old,@SourceId,@StateId_Old,@StateId,
	 @TypeId_Old,@TypeId,@IndustryOneId_Old,@IndustryOneId,@IndustryTwoId_Old,@IndustryTwoId,@Zip_Old,@Zip,
	 @WebAddress_Old,@WebAddress,@Fax_Old,@Fax)

End